技术专题-OPC访问 三菱Q系列PLC 方法
技术专题-OPC访问 三菱Q系列PLC 方法
Author: ChonggaoYu QQ: Email:tjycg@163.com 2011.11.07
一、Q 系列PLC经典配置例:
二、PLC编程器件
三、PLC过程控制程序设计的方法
四、上位机 对PLC 数据的读写( 控制数据写入,和 控制数据的读出)
五、VS008通过OPC server PLC访问的方法
一、Q 系列PLC经典配置例:
带串口,以太网络,16点输入,16点输出
位置 | 0 | 1 | 2 | 3 | 4 | 5 | |
模块 |
电源 (固定) Q62P |
CPU (固定) Q02CPU |
串口 QJ71C24N |
网络 QJ71E71-100 |
CCLINK QJ61BT11N |
输入 QX40 |
输出 QY40P |
32位 | 32位 | 32位 | 16位 | 16位 | |||
地址 | 0 | 20 | 40 | 60 | 70 | ||
程序访问地址 | X60 | X70 |
二、PLC编程器件
一般情况下,X代表输入继电器,Y代表输出继电器,M代表辅助继电器,SPM代表专用辅助继电器,T代表定时器,C代表计数器,S代表状态继电器,D代表数据寄存器,MOV代表传输等。
X |
输入继电器 (16位) |
输入指示灯显示硬件的实际 ON/OFF状态(ON灯亮,OFF灯灭)。如果编程修改X值,与实际硬件输入不一致时,虽然指示灯不显示,但是在程序中已经有效。 | |
Y |
输入继电器 (16位) |
||
M | 辅助继电器 | ||
T | 定时器 | ||
C | 计数器 | ||
D |
数据寄存器 (16位) |
负数是补码形式存储的。 D800-D999 断电可以记忆的寄存器 通过OPCserver读取速度测试,读200个寄存器耗时0.125S |
注:称重仪表Panther表设定PLC的寄存器地址,表的重量数据可以直接写入编程控制点,PLC程序直接读取就可以了。如何设置?
三、PLC过程控制程序设计的方法
1) 手工 编写PLC程序
2) 通过 编程工具,编写T形图,写入PLC。
四、上位机 对PLC 数据的读写( 控制数据写入,和 控制数据的读出)
1) 通过编程软件(软件:VS2005/VS2008),调用 OPC Server库(Interop.ACTMULTILib.dll, Interop.ACTSUPPORTLib.dll),向PLC 读出或者写入 数据(编程器件),
需要配置OPC Server .软件:MELSOFT Application -> MX component -> Communication Utility.
(opc server也可以访问PLC的数据 软件: MELSOFT Application -> MX component -> PLC Monitor Utility).
图Communication Utility.
图PLC Monitor Utility 1/2 监视
图PLC Monitor Utility 2/2 设置值
2) 通过组态软件,调用 OPC Server库,向PLC 读出或者写入 数据(编程器件)。
(缺点,组态软件不是针对一种PLC设备,处理速度慢,读写数据速度延迟几秒)
五、VS008通过OPC server PLC访问的方法
5.1 在解决方案中添加 opc server dll库
Interop.ACTMULTILib.dll
Interop.ACTSUPPORTLib.dll
5.2 读写程序代码
//1 引用PLC库
using ACTMULTILib; // 引用 PLC 库 for PLC MITSUBISHI
using ACTSUPPORTLib; //引用 PLC 库 for PLC MITSUBISHI
//2定义 PLC Station
ActEasyIFClass PLC_Station = new ActEasyIFClass(); //定义PLC Station
PLC_Station.ActLogicalStationNumber = 1; // Set Logic Station Number
//3 关闭打开 PLC Station
PLC_Station.Close();
int intRet = PLC_Station.Open(); // Open PLC
//Check PLC Open Result
if (intRet == 0) // -------------------------PLC Open OK
{
//MessageBox.Show("PLC Open OK!");
}
else // -------------------------------------PLC Open NG
{
Tx_RecData.Text = "PLC Open NG!";
return ;
//MessageBox.Show("PLC Open NG!");
}
// 4 读PLC 控制点值(多个)
int[] intTmp = new int[] { 0, 0, 0, 0 };
if (PLC_Station.ReadDeviceRandom("X60\nX61\nX62\nX63\n", 4, out intTmp[0]) == 0)
{ //读出正确
Tx_RecData.Text = intTmp[0].ToString() + "," + intTmp[1].ToString() + "," + intTmp[2].ToString() + "," + intTmp[3].ToString();
}
Else //读出出错
{
Tx_RecData.Text = "读PLC 出错";
}
//5 写PLC 控制点(多个)
//intRet = PLC_Station.Close();
int []intTmp = new int[]{0,0,0,0};
string[] stri = TB_WriteValue.Text.Trim().Split(',');
int i=0;
for (; i < stri.Length; i++)
{
intTmp[i] = int.Parse(stri[i].Trim());
}
string StrAdd = Tb_WriteAdd.Text.Trim().Replace(" ","").Replace(",","\n")+"\n";
//eg. StarAdd = "D100\nD101\nD102\nD103\n"; 注意控制点与数值数目一致
//eg. StarAdd = "X60\nX61\n";
intRet = PLC_Station.WriteDeviceRandom(StrAdd, i, ref intTmp[0]);
TB_Status.Text = "";
if (intRet != 0)
{
TB_Status.Text = "Write PLC Error";
}
图读写简单例子